package com.gdut.simple.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.data.entity.Gank;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

public class GankAdapter extends AbsRecyclerAdapter<Gank> {

    public GankAdapter(Context context, List<Gank> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mInflater.inflate(R.layout.layout_gank_item, parent, false));
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        final ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.desc.setText(mData.get(position).getDesc());
        viewHolder.type.setText(mData.get(position).getType());
        viewHolder.time.setText(convertTime(mData.get(position).getPublishedAt()));
    }

    private String convertTime(String time) {
        return time.substring(0, time.indexOf("T"));
    }

    private static class ItemViewHolder extends AbsViewHolder {

        TextView desc;
        TextView type;
        TextView time;

        ItemViewHolder(View itemView) {
            super(itemView);
            desc = (TextView) itemView.findViewById(R.id.id_info_desc);
            type = (TextView) itemView.findViewById(R.id.id_info_type);
            time = (TextView) itemView.findViewById(R.id.id_info_time);
        }
    }

}
